]> dgit.raspbian.org Git - gnome-shell.git/commitdiff
hotplut-sniffer: Use one-shot idle/timeout functions
authorFlorian Müllner <fmuellner@gnome.org>
Thu, 29 Jan 2026 13:29:58 +0000 (14:29 +0100)
committerMarge Bot <marge-bot@gnome.org>
Thu, 29 Jan 2026 15:16:05 +0000 (15:16 +0000)
GLib added one-shot variants of the idle/timeout functions a while ago.

While they don't save a lot of code, they serve as a clear marker that
the callback is only invoked once.

Part-of: <https://gitlab.gnome.org/GNOME/gnome-shell/-/merge_requests/3947>

src/hotplug-sniffer/hotplug-sniffer.c
src/hotplug-sniffer/shell-mime-sniffer.c

index 4b70ec72a014e93541c82445b501e4f8d27e25b6..9291fc25eea8f56d431f50390ab6932356ead15a 100644 (file)
@@ -43,15 +43,13 @@ static GDBusNodeInfo *introspection_data = NULL;
 static GMainLoop     *loop = NULL;
 static guint          autoquit_id = 0;
 
-static gboolean
+static void
 autoquit_timeout_cb (gpointer _unused)
 {
   print_debug ("Timeout reached, quitting...");
 
   autoquit_id = 0;
   g_main_loop_quit (loop);
-
-  return FALSE;
 }
 
 static void
@@ -69,9 +67,9 @@ ensure_autoquit_on (void)
   if (g_getenv ("HOTPLUG_SNIFFER_PERSIST") != NULL)
     return;
 
-  autoquit_id = 
-    g_timeout_add_seconds (AUTOQUIT_TIMEOUT,
-                           autoquit_timeout_cb, NULL);
+  autoquit_id =
+    g_timeout_add_seconds_once (AUTOQUIT_TIMEOUT,
+                                autoquit_timeout_cb, NULL);
   g_source_set_name_by_id (autoquit_id, "[gnome-shell] autoquit_timeout_cb");
 }
 
@@ -139,7 +137,7 @@ handle_sniff_uri (InvocationData *data)
 
   ensure_autoquit_off ();
 
-  g_variant_get (data->parameters, 
+  g_variant_get (data->parameters,
                  "(&s)", &uri,
                  NULL);
   file = g_file_new_for_uri (uri);
index 724a204c384c81526824f46eb6f966998ca305bd..b4d6d43899cfbcd0d7bf5fcbc8d2b398a19e370a 100644 (file)
@@ -439,15 +439,13 @@ query_info_async_ready_cb (GObject *source,
   deep_count_start (self);
 }
 
-static gboolean
+static void
 watchdog_timeout_reached_cb (gpointer user_data)
 {
   ShellMimeSniffer *self = user_data;
 
   self->watchdog_id = 0;
   g_cancellable_cancel (self->cancellable);
-
-  return FALSE;
 }
 
 static void
@@ -565,8 +563,8 @@ shell_mime_sniffer_sniff_async (ShellMimeSniffer *self,
                            callback, user_data);
 
   self->watchdog_id =
-    g_timeout_add (WATCHDOG_TIMEOUT,
-                   watchdog_timeout_reached_cb, self);
+    g_timeout_add_once (WATCHDOG_TIMEOUT,
+                        watchdog_timeout_reached_cb, self);
   g_source_set_name_by_id (self->watchdog_id, "[gnome-shell] watchdog_timeout_reached_cb");
 
   start_loading_file (self);